<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class GoodsParames extends Model
{
    use SoftDeletes;
    protected $table = 'goods_params';
    protected $fillable=[ 'name', 'value', 'type', ];

    protected $appends = ['value_text'];

    public function manyType()
    {
        return $this->belongsToMany(GoodsType::class,'goods_type_params','params_id','type_id');
    }

    /**
     * @return array
     * 参数 字符串转数组
     */
    public function getValueTextAttribute()
    {
        if(!empty($this->value))
        {
            return explode(',',$this->value);
        }
        return [];
    }
}
